/*
 * Copyright � 2008 Nokia Corporation.
 */

#ifndef __SUDOKUAPPVIEW_h__
#define __SUDOKUAPPVIEW_h__

// INCLUDES
#include <coecntrl.h>
#include <fbs.h>

#include "SudokuMenuControl.h"

#define START_DELAY  60000
#define DELAY        60000

class CSudokuGameLogic;
class CSudokuGridControl;
class CSudokuBtnControl;
class CSudokuStatisticControl;
class CGraphicEngine;
class CSudokuMenuControl;
class CSudokuAppUi;

enum EAnimationType
    {
    ENoType = 0,
    EContinuouslyScreenDrawing
    };

// CLASS DECLARATION
class CSudokuContainerControl : public CCoeControl, public MSudokuMenuControlObserver
    {
    public:
        static CSudokuContainerControl* NewL (const TRect& aRect );
        static CSudokuContainerControl* NewLC (const TRect& aRect );
        virtual ~CSudokuContainerControl ( );
    
    public:
        inline CSudokuGameLogic* GameLogic(){return iGameLogic;};
        inline CSudokuGridControl* GridControl(){return iGridControl;};
        inline CSudokuBtnControl* BtnControl(){return iBtnControl;};
        inline CSudokuMenuControl* MenuControl(){return iSudokuMenu;};
        inline CSudokuStatisticControl* StatisticControl(){return iStatisticControl;};
        inline CFont* GridFont(){return iFont;};
        inline CFont* StatisticFont(){return iFont2;};
        inline CFont* StatisticMinorFont(){return iFont3;};
        void CreateFontsL();
        void UseFont(CFont* aFont);
        void DrawBackground();
        void CbaSizeChanged();
        void StartFrameUpdateL(EAnimationType aType, TInt startDelay);
        void StopFrameUpdate();        
        #ifndef __WINS__
        TCoeInputCapabilities InputCapabilities() const;
        #endif
        
    private:
        void ConstructL (const TRect& aRect );
        CSudokuContainerControl();
        void HandlePointerEventL(const TPointerEvent& aPointerEvent);
        void Draw (const TRect& aRect ) const;
        void SizeChanged();
        void HandleResourceChange(TInt aType);
        TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
        
    private:
        void CreateBackBufferL();
        void ReleaseBackBuffer();
        static TInt DoFrame(TAny* aObj);
        static TInt DoNewGame(TAny* aObj);
        void DoDraw();
        void CalBtnCtrlPosition();
        

    public: // From MSudokuMenuControlObserver
        void MenuItemSelected(TInt aIndex);    
        
    private:
        CFbsBitmap*                         iBackBuffer;
        CFbsBitmapDevice*                   iBackBufferDevice;
        CFbsBitGc*                          iBackBufferContext;
        TSize                               iBackBufferSize;
        
        CPeriodic*                          iPeriodic; 
        CSudokuGameLogic*                   iGameLogic;
        CSudokuGridControl*                 iGridControl;
        CSudokuBtnControl*                  iBtnControl;
        CSudokuStatisticControl*            iStatisticControl;
        TRect                               iBtnCtrlRect;
        CFont*                              iFont; // for the grid
        CFont*                              iFont2; // for the statistic default
        CFont*                              iFont3; // for the statistic little
        CGraphicEngine*                     iGraphicEngine;
        TRect                               iLogoRect;
        
        CSudokuMenuControl*                 iSudokuMenu;
        CSudokuAppUi*                       iAppUi;

        TRect                               iOptionsCbaPoint;
        TRect                               iBackCbaPoint;
        TRect                               iExitCbaPoint;
        HBufC16*                            iOptionsTxt;
        HBufC16*                            iSelectTxt;
        HBufC16*                            iBackTxt;
        HBufC16*                            iExitTxt;
        
        EAnimationType                      iAnimationType;
        TInt                                iCleanConfictsCounter;
    };

#endif // __SUDOKUAPPVIEW_h__

// End of File
